//
//  ChangePasswordViewController.m
//  LineMoney
//
//  Created by 尹宁 on 16/7/18.
//  Copyright © 2016年 范琦. All rights reserved.
//

#import "ChangePasswordViewController.h"
#import "ChangePasswordTableViewCell.h"

@interface ChangePasswordViewController ()<UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *arr;
@end

@implementation ChangePasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"修改密码";
    [self creatTableView];
    
    _arr = [NSMutableArray array];
//    UIButton *right = [UIButton buttonWithType:UIButtonTypeCustom];
//    right.frame = CGRectMake(0, 0, 40, 20);
//    [right setTitle:@"保存" forState:UIControlStateNormal];
//    [right setTintColor:[UIColor whiteColor]];
//    self.navigationItem.rightBarButtonItem = right;
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
    self.tabBarController.tabBar.hidden = YES;
    
}

- (void)creatTableView
{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, -20, KSCREENWIDTH, KSCREENHEIGHT) style:UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView registerNib:[UINib nibWithNibName:@"ChangePasswordTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:_tableView];
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.backgroundColor = [UIColor whiteColor];
    _tableView.sectionFooterHeight = 0;
    
}


#pragma mark - TableView代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ChangePasswordTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.SmallLabel.textColor = BACKGROUNDCOLOR;
    cell.LineLabel.backgroundColor = [UIColor colorWithRed:238 / 255.0 green:238 / 255.0 blue:238 / 255.0 alpha:1];
    cell.ChangeButton.hidden = YES;
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    [_arr addObject:cell.InputTextfield];
    cell.InputTextfield.delegate = self;
    cell.InputTextfield.tag = indexPath.row + 1000;

    if (indexPath.row == 0) {
        cell.SmallLabel.text = @"当前密码";
        [cell.InputTextfield becomeFirstResponder];
        cell.LineLabel.backgroundColor = BACKGROUNDCOLOR;
        cell.InputTextfield.placeholder = @"请输入当前密码";
    } else if (indexPath.row == 1) {
        cell.SmallLabel.text = @"新密码";
        cell.InputTextfield.placeholder = @"请输入新密码";
    } else if (indexPath.row == 2) {
        cell.SmallLabel.text = @"再次输入密码";
        cell.InputTextfield.placeholder = @"请再次输入密码";
    }
    return cell;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    
    for (UITextField *text in _arr) {
        if (textField == text) {
            ChangePasswordTableViewCell *cell = [_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:textField.tag - 1000 inSection:0]];
            cell.LineLabel.backgroundColor = BACKGROUNDCOLOR;
        } else {
            ChangePasswordTableViewCell *cell = [_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:text.tag - 1000 inSection:0]];
            cell.LineLabel.backgroundColor = [UIColor colorWithRed:238 / 255.0 green:238 / 255.0 blue:238 / 255.0 alpha:1];
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
